<template>
  <div>
    <el-row :gutter="12">
      <el-col class="card-item" :xs="24" :sm="12" :lg="6">
        <el-card class="box-card in">
          <div class="clearfix">
            <div class="fl">
              <p>本月进件</p>
              <p class="count">6399</p>
              <p>+20.12% <span>与上月同比</span></p>
            </div>
            <div class="fr"><i class="el-icon-tickets ico"></i></div>
          </div>
        </el-card>
      </el-col>
      <el-col class="card-item" :xs="24" :sm="12" :lg="6">
        <el-card class="box-card out">
          <div class="clearfix">
            <div class="fl">
              <p>本月放贷</p>
              <p class="count">121000000</p>
              <p>+1.25% <span>与上月同比</span></p>
            </div>
            <div class="fr"><i class="el-icon-money ico"></i></div>
          </div>
        </el-card>
      </el-col>
      <el-col class="card-item" :xs="24" :sm="12" :lg="6">
        <el-card class="box-card allin">
          <div class="clearfix">
            <div class="fl">
              <p>累计进件</p>
              <p class="count">128700</p>
              <p>+11.48% <span>与上月同比</span></p>
            </div>
            <div class="fr"><i class="el-icon-date ico"></i></div>
          </div>
        </el-card>
      </el-col>
      <el-col class="card-item" :xs="24" :sm="12" :lg="6">
        <el-card class="box-card allout clearfix">
          <div class="clearfix">
            <div class="fl">
              <p>累计放贷</p>
              <p class="count">923380079</p>
              <p>-2.06% <span>与上月同比</span></p>
            </div>
            <div class="fr"><i class="el-icon-coin ico"></i></div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <!-- 图表展示 -->
    <el-row class="mt" :gutter="24">
      <el-col :sm="24" :lg="16" :xs="0">
        <el-card>
          <div slot="header" style="text-align:center">
            <span>进件统计分析</span>
          </div>
          <!-- 进件分析图表 -->
          <div class="wrap" style="width:800px"> 
            <div style="height: 240px;" ref="analysis"></div>
          </div>
        </el-card>
      </el-col>
      <el-col :sm="24" :lg="8" :xs="24">
        <el-card>
          <div slot="header" style="text-align:center">
            <span>进件产品占比</span>
          </div>
          <!-- 绘制饼状图 -->
          <div class="wrap" style="width:400px">
            <div ref="percent" style="height: 240px;"></div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-row class="mt" :gutter="12">
      <el-col :sm="24" :lg="12" :xs="24">
        <div class="block">
          <el-timeline>
            <el-timeline-item timestamp="2018/4/12" placement="top">
              <el-card>
                <h4>更新 Github 模板</h4>
                <p>王小虎 提交于 2018/4/12 20:46</p>
              </el-card>
            </el-timeline-item>
            <el-timeline-item timestamp="2018/4/3" placement="top">
              <el-card>
                <h4>更新 Github 模板</h4>
                <p>王小虎 提交于 2018/4/3 20:46</p>
              </el-card>
            </el-timeline-item>
            <el-timeline-item timestamp="2018/4/2" placement="top">
              <el-card>
                <h4>更新 Github 模板</h4>
                <p>王小虎 提交于 2018/4/2 20:46</p>
              </el-card>
            </el-timeline-item>
            <el-timeline-item timestamp="2018/4/2" placement="top">
              <el-card>
                <h4>更新 Github 模板</h4>
                <p>王小虎 提交于 2018/4/2 20:46</p>
              </el-card>
            </el-timeline-item>
            <el-timeline-item timestamp="2018/4/2" placement="top">
              <el-card>
                <h4>更新 Github 模板</h4>
                <p>王小虎 提交于 2018/4/2 20:46</p>
              </el-card>
            </el-timeline-item>
          </el-timeline>
        </div>
      </el-col>
      <el-col  :sm="24" :lg="12" :xs="24">
        <el-calendar v-model="value"> </el-calendar>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { get } from "@/utils/http.js";
export default {
  data() {
    return {
      chartList: [],
      value: new Date()
    };
  },
  computed: {
    // 左侧线性图配置
    option() {
      let chartData = this.chartList[0];

      let options = {
        xAxis: {
          type: "category",
          data: chartData.dateX,
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: chartData.values,
            type: "line",
            smooth: true,
            areaStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "#4f88ff", // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "white", // 100% 处的颜色
                  },
                ],
                global: false, // 缺省为 false
              },
            },
          },
        ],
      };
      return options;
    },
    // 右侧饼状图配置
    option1() {
      let options1 = {
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b}: {c} ({d}%)",
        },
        legend:{
          top:'5%',
          left:'center'
        },
        series: [
          {
            name: "访问来源",
            type: "pie",
            radius: ["50%", "70%"],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: "center",
            },
            emphasis: {
              label: {
                show: true,
                fontSize: "30",
                fontWeight: "bold",
              },
            },
            labelLine: {
              show: false,
            },
            data: [
              { value: 335, name: "房闪贷" },
              { value: 310, name: "新车贷" },
              { value: 234, name: "资金贷" },
              { value: 135, name: "合力贷" },
              { value: 1548, name: "其他" },
            ],
          },
        ],
      };
      return options1;
    },
  },

  mounted() {
    get("/chart").then((res) => {
      this.chartList = res.data;
      console.log(this.chartList);
      this.drawLine();
      this.drawPie();
    });
  },
  methods: {
    drawLine() {
      let myChart = this.$echarts.init(this.$refs["analysis"]);
      myChart.setOption(this.option);
    },
    drawPie() {
      let myChart = this.$echarts.init(this.$refs["percent"]);
      myChart.setOption(this.option1);
    },
  },
};
</script>

<style lang="less" scoped>
.box-card {
  width: 300px;
  color: #fff;
  p {
    line-height: 30px;
    font-size: 14px;
    span {
      font-size: 12px;
    }
  }
  .count {
    font-weight: bold;
  }
}
.wrap{
  margin: auto;
}
.allin {
  background: #5050ff;
}
.allout {
  background: #f49b3b;
}
.in {
  background: #4f88ff;
}
.out {
  background: #f26075;
}
.ico {
  float: right;
  font-size: 90px;
  color: rgba(255, 255, 255, 0.3);
}
.block {
  background-color: #fff;
  padding: 10px 15px;
}
</style>
